package nl.hva.three2learn.controller.event;

import nl.hva.three2learn.model.Chapter;
import nl.hva.three2learn.model.Course;
import nl.hva.three2learn.model.Event;
import nl.hva.three2learn.model.LiveSession;
import nl.hva.three2learn.model.Topic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;

public class EventFactory {

	@Autowired
	private MessageSource messageSource;
	
	public Event createCourseCreatedEvent(Course course) {
		
		Event e = new Event(
				"event.course.new.title", 
				"event.course.new.description",
				"/course/" + course.getId()
			);
		
		e.setParams(new String[] {
				course.getCategory().getName(),
				course.getName()
			});
		
		return e;
	}
	
	public Event createChapterAddedEvent(Chapter chapter) {
		
		Event e = new Event(
					"event.chapter.new.title",
					"event.chapter.new.description"
				);
		
		e.setParams(new String[] { 
				chapter.getTitle(), 
				chapter.getCourse().getName() 
			});
		
		return e;
	}
	
	public Event createTopicCreatedEvent(Topic topic) {
		
		Event e = new Event(
					"event.topic.new.title",
					"event.topic.new.description",
					topic.getCourse().getId() + "/forum/" + topic.getId()
				);
		
		e.setParams(new String[] {
				topic.getCourse().getName(),
				topic.getTitle()
			});
		
		return e;
	}
	
	public Event createLiveSessionStartedEvent(LiveSession liveSession) {
		
		Event e = new Event(
					"event.livesession.new.title",
					"event.livesession.new.description",
					"/course/live/view/" + liveSession.getId()
				);
		
		e.setParams(new String[] {
				liveSession.getTeacher().getFullName(),
				liveSession.getTitle()
			});
		
		return e;
	}
	
}
